package util;

import static java.lang.Math.abs;

/**
 * 
 */
public class TestFunctions {
	public static float max(float f, float g) {
		return f >= g ? f : g;
	}

	public static float min(float f, float g) {
		return f < g ? f : g;
	}
	public static boolean array_equal(float[] one, float[] two) {
		for (int i = 0; i < two.length; i++) {
			if (one[i] != two[i])
				return false;
		}
		return true;
	}

	/**
	 * 
	 * @return
	 */
	public static boolean almost_equal(float[] one, float[] two, int l) {
		return almost_equal(one, two, l, 0.001f);
	}

	/**
	 * Tests if two arrays are almost equal, testing method for results with
	 * numerical faults
	 * 
	 * @return
	 */
	public static boolean almost_equal(float[] one, float[] two, int l,
			float diff) {
		for (int i = 0; i < l; i++) {
			if (!kindof_equal(one[i], two[i], diff))
				return false;
		}
		return true;
	}

	/**
	 * function that checks if one and two match (two -
	 * diff*two)<one&&(two+two*diff)>one;
	 * 
	 * @param diff
	 *            percentage one and two may be apart
	 */
	public static boolean kindof_equal(float one, float two, float diff) {
		return (two - abs(diff * two)) < one && (two + abs(two * diff)) > one;
	}
}
